package site.jlopen.assets.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import site.jlopen.assets.config.interceptor.OssInterceptor;

@Configuration
public class MvcConfigurer implements WebMvcConfigurer {

	@Value("${file.local.dir}")
	private String baseDir;

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		InterceptorRegistration ossInterceptor = registry.addInterceptor(getOssInterceptor());
		ossInterceptor.addPathPatterns("/oss/**");
		
		/*InterceptorRegistration uiInterceptor = registry.addInterceptor(getUiInterceptor());
		uiInterceptor.addPathPatterns("/**");*/
	}

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/oss/**").addResourceLocations("file:" + baseDir);
	}

	@Bean
	public OssInterceptor getOssInterceptor() {
		return new OssInterceptor();
	}

	/*@Bean
	public UiInterceptor getUiInterceptor() {
		return new UiInterceptor();
	}*/
}
